<template>
  <div>
    <!-- 主体部分 -->
    <section class="main">
      <input id="toggle-all" class="toggle-all" type="checkbox" />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list">
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <li
          :class="{ completed: item.isDone }"
          v-for="item in list"
          :key="item.id"
        >
          <div class="view">
            <!-- 双向绑定并注册点击事件: 选中后, 将绑定的数据传递给父组件, 让父组件修改数组数据 -->
            <input
              class="toggle"
              type="checkbox"
              @change="$emit('handlechange', item.id)"
              :checked="item.isDone"
            />
            <label>{{ item.name }}</label>
            <!-- 点击删除: 子传父删除数据 -->
            <button class="destroy" @click="$emit('delete', item.id)"></button>
          </div>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      required: true,
      type: Array,
    },
  },
  data() {
    return {
    };
  },
  methods: {

  },
};
</script>

<style>
</style>